/*
 * @Author: szx
 * @Date: 2022-03-28 14:12:23
 * @LastEditTime: 2022-03-28 14:12:23
 * @Description: 
 * @FilePath: \leetcode\剑指offer\58\58_II.js
 */
/**
 * @param {string} s
 * @param {number} n
 * @return {string}
 */
 var reverseLeftWords = function (s, n) {
    const arr = Array.from(s);
    reverse(arr, 0, n - 1);
    reverse(arr, n, arr.length - 1);
    reverse(arr, 0, arr.length - 1);
    return arr.join('');
};
const reverse = function (strArr, l, r) {
    while (l < r) {
        [strArr[l], strArr[r]] = [strArr[r], strArr[l]];
        l++;
        r--;
    }
};